package com.distribute.application.api.task;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.distribute.framework.model.TbBalanceStatistics;

@Component("TimerWater")
public class TimerWater {
	private static Logger log = LoggerFactory.getLogger(TimerWater.class);
	public SimpleDateFormat now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	@Scheduled(cron = "0 10 0 1 * ?")
	public void GetWaterRealTimeData(){
		MyThread t=new MyThread();
		t.start();
	}
	class MyThread extends Thread{
		public MyThread(){
			super();
		}
		public void run(){
			log.info("TimeWater:执行更新实时数据, 开始" + now.format(new Date()));
			System.err.println("===========TimeWater: 执行更新实时数据, 开始");
			doNewInfo();
			log.info("TimeWater: 执行更新实时数据, 结束" + now.format(new Date()));
			System.err.println("===========TimeWater: 执行更新实时数据, 结束......");
			
		}
	}
	public void doNewInfo(){
		List<TbBalanceStatistics> balanceStatistics=TbBalanceStatistics.where.list(10000);
		for (TbBalanceStatistics tbBalanceStatistics : balanceStatistics) {
			Integer count=tbBalanceStatistics.getTbbsNowMonthSurplus();
			tbBalanceStatistics.setTbbsOldMonthMargin(count);
			tbBalanceStatistics.setTbbsNowMonthBuy(0);
			tbBalanceStatistics.setTbbsNowMonthSend(0);
			tbBalanceStatistics.setTbbsNowMonthSurplus(0);
			tbBalanceStatistics.update();
		}
	}
}
